<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>promise</div>
    <script>
        var a = 1;
        // setTimeout(() => {
        //     a = 2
        //     setInterval(() => {
        //         a = 3
        //         console.log(a);
        //     }, 1000);
        // }, 1000);
        function timeOut() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    a = 2
                    resolve(a)
                }, 1000)
            })
        }
        function timeOut2() {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    a = 3
                    // reject(`a出错了：${a}`)
                    resolve(a)
                }, 1000)
            })
        }
        timeOut().then(a => {
            console.log(a);
        }).then((ress) => {
            timeOut2().then(res => {
                console.log(res);
                console.log(ress);
                return res;
            })
        }).then(res => {

        }).catch(err => {
            console.log(err);
        })
    </script>
</body>

</html>